const mongoose = require('../utils/db')

const goodSchema = new mongoose.Schema({
    jewelryType: String,
    series: String,
    price: Number,
    name: String,
    img: String,
    model: String,
    salesval: Number,
    desc: String,
    size: String,
    elseSpecs: String,
    choose: String
})
var Goods = mongoose.model('goods', goodSchema)
    // 查询所有
const findAllGoods = () => {
    // 从数据库里拿到list
    return new Promise((resolve, reject) => {
        Goods.find((err, docs) => {
            if (err) reject(err)
            else resolve(docs)
        })
    })
}
const findOneGood = (_id) => {
    // 从数据库里拿到list
    return new Promise((resolve, reject) => {
        Goods.find(_id, (err, docs) => {
            if (err) reject(err)
            else resolve(docs[0])
        })
    })
}

module.exports = {
    findAllGoods,
    findOneGood
}